<?php

namespace common\models\tsline;

use Yii;
use common\models\member\Member;

/**
 * This is the model class for table "{{%ts_bloger}}".
 *
 * @property int $id
 * @property int $user_id 用户ID
 * @property string $name 名称
 * @property string $avatar LOGO
 * @property string $cover 背景图片
 * @property string $description 简介
 * @property int $vip_time
 * @property int $verify_time 认证时间
 * @property int $status 状态
 * @property string $mark 备注
 * @property int $created_at 创建时间
 * @property int $updated_at 更新时间
 * @property int $deleted_at 删除时间
 */
class TslineBloger extends \yii\db\ActiveRecord {

    use \common\traits\Constants;
    use \common\traits\TimestampBehavior;

    const STATUS_DEFAULT = 0;
    const STATUS_SUCCESS = 1;
    const STATUS_FAIL = -1;

    /**
     * @inheritdoc
     */
    public static function tableName() {
        return '{{%ts_bloger}}';
    }

    /**
     * @inheritdoc
     */
    public function rules() {
        return [
            [['user_id', 'vip_time', 'verify_time', 'status', 'created_at', 'updated_at', 'deleted_at', 'is_offical'], 'integer'],
            [['name'], 'required'],
            [['name'], 'string', 'max' => 50],
            [['avatar', 'cover'], 'string', 'max' => 128],
            [['description', 'mark'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels() {
        return [
            'id' => 'ID',
            'user_id' => '用户ID',
            'name' => '名称',
            'avatar' => 'LOGO',
            'cover' => '背景图片',
            'description' => '简介',
            'vip_time' => 'Vip Time',
            'verify_time' => '认证时间',
            'status' => '状态',
            'is_offical' => '是否官方',
            'mark' => '备注',
            'created_at' => '创建时间',
            'updated_at' => '更新时间',
            'deleted_at' => '删除时间',
        ];
    }

    public function getUser() {
        return $this->hasOne(Member::className(), ['uid' => 'user_id']);
    }

    public function afterFind() {
        parent::afterFind();
        $this->avatar = Yii::getAlias('@attachUrl') . $this->avatar;
    }

}
